﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace YSC_Core.BLL.Repository
{
    public interface IEfRepository
    {
        /// <summary>
        /// where方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IQueryable<T> Where<T>(Expression<Func<T, bool>> predicate) where T : class, new();
        /// <summary>
        /// 获取第一或默认
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="includeProperties"></param>
        /// <returns></returns>
        T FirstOrDefault<T>(Expression<Func<T, bool>> includeProperties) where T : class, new();

        /// <summary>
        /// 执行SQL获取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        IEnumerable<T> SqlQuery<T>(string sql, params object[] parameters) where T : class, new();

        /// <summary>
        /// 高效批量插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entities"></param>
        void BulkInsert<T>(IList<T> entities) where T : class, new();

        /// <summary>
        /// Insert entity
        /// </summary>
        /// <param name="entity">Entity</param>
        void Insert<T>(T entity) where T : class, new();

        /// <summary>
        /// Insert entities
        /// </summary>
        /// <param name="entities">Entities</param>
        void InsertList<T>(IEnumerable<T> entities) where T : class, new();

        /// <summary>
        /// Update entity
        /// </summary>
        /// <param name="entity">Entity</param>
        void Update<T>(T entity) where T : class, new();

        /// <summary>
        /// Update entities
        /// </summary>
        /// <param name="entities">Entities</param>
        void UpdateList<T>(IEnumerable<T> entities) where T : class, new();


        /// <summary>
        /// 删除单个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        void Remove<T>(T entity) where T : class, new();

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entities"></param>
        void RemoveRange<T>(IEnumerable<T> entities) where T : class, new();
    }
}
